/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DCGTree;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 *
 * @author Raito
 */
public class Parser {

    public Node ParseSentence(String syntax) {
        Node root;
        List<String> formatX = new ArrayList<String>();
        StringParse stringParse = new StringParse(syntax);
        stringParse.formatString();

        stringParse.getToken();
        formatX = stringParse.getFormatX();
        String parent = "";
        List<String> child = new ArrayList<String>();
        int index = 0;
        Stack<Node> stack = new Stack<Node>();
        for (String s : formatX) {

            if ("(".equals(s) || ")".equals(s) || ",".equals(s)) {
            } else {
                parent = stringParse.findParent(s, index);
                child = stringParse.findChild(index);
                Node node = new Node(s);
                stack.add(node);

            }
            if (")".equals(s)) {
            }

            index++;
        }

        root = stringParse.parseToTree();
        return root;
    }
}
